import pandas as pd
import struct

input_file = 'out_data_files/1-output-水位库容.bin'
output_file = 'out_data_files/1-output-水位库容.xlsx'

with open(input_file, 'rb') as input_f:
    data = input_f.read()

# 解析二进制数据
water_levels = []
capacities = []


for i in range(0, len(data), 8):  # 每个水位和库容占用8个字节
    water_level_bytes = data[i:i + 4]
    capacity_bytes = data[i + 4:i + 8]

    water_level = struct.unpack('!f', water_level_bytes)[0]
    capacity = struct.unpack('!f', capacity_bytes)[0]


    water_level = round(water_level, 2) # 保留两位
    capacity = round(capacity, 2)

    water_levels.append(water_level)
    capacities.append(capacity)


df = pd.DataFrame({
    '水位（米）': water_levels,
    '库容（万立方米）': capacities
})


df.to_excel(output_file, index=False)

print(f"files:  {output_file}")
